﻿using L005_Controller.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace L005_Controller.Controllers
{
    public class DefaultController : Controller
    {
        Model1 model = new Model1();

        // GET: Default
        public ActionResult Index()
        {
            var list = model.Task.ToList();
            return View(list);
        }
        public ActionResult Detail(int id)
        {   
            Task task = model.Task.FirstOrDefault(p => p.TaskID == id);
            return View(task);
        }
        [HttpPost] //不允许get类型访问
        public ActionResult Del(int id)
        {
            Task task = model.Task.FirstOrDefault(p => p.TaskID == id);
            if (task!=null)
            {
                model.Task.Remove(task);
               var result= model.SaveChanges()>0;
                return Json(result);
            }
            return Json(false);
        }

    }
}